package com.example.demo.data.db;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import java.time.LocalDateTime;
import java.util.function.Consumer;

import lombok.extern.slf4j.Slf4j;

/**
 * @author jiangjinwu
 * @version 1.0
 * @since 2025/10/8 23:56
 */

@Slf4j

public class ResultHandler {

  public void handler(String result, Long key, Consumer<TaskProcessResult> function) {
    JSONObject jsonObject =JSONUtil.parseObj( result);
    TaskProcessResult taskProcessResult = TaskProcessResult.builder()
        .code(jsonObject.getStr("code"))
        .message(jsonObject.getStr("message"))
        .traceId(jsonObject.getStr("traceId"))
        .finishAt(LocalDateTime.now())
         .id(key)
        .build();
    function.accept(taskProcessResult);
  }
}
